package org.infodavid.common.registry;

import java.io.Serializable;
import java.util.Collection;

/**
 * The Interface IRegistry.
 * @param <K> the type of the keys
 * @param <E> the type of the elements
 */
public interface IRegistry<K extends Serializable,E extends Serializable> {

	/**
	 * Clear.
	 */
	void clear();

	/**
	 * Gets the entries.
	 * @return the registered entries (unmodifiable)
	 */
	Collection<E> getEntries();

	/**
	 * Gets the entry.
	 * @param key the key
	 * @return the entry associated to the given key
	 */
	E getEntry(final K key);

	/**
	 * Register.
	 * @param elt the entry to register
	 * @return the registered entry or null
	 */
	E register(final E elt);

	/**
	 * Unregister.
	 * @param elt the entry to unregister
	 * @return the unregistered entry or null
	 */
	E unregister(final E elt);

	/**
	 * Gets the entries count.
	 * @return the number
	 */
	long size();

	/**
	 * Check if the registry contains the entry using its key.
	 * @param key the key
	 * @return true if registry contains the entry.
	 */
	boolean containsKey(K key);

	/**
	 * Check if the registry contains the entry.
	 * @param entry the entry
	 * @return true if registry contains the entry.
	 */
	boolean containsEntry(E entry);

	/**
	 * Gets the listener.
	 * @return the listener
	 */
	IRegistryListener<K,E> getListener();

	/**
	 * Sets the listener.
	 * @param lsnr the listener
	 */
	void setListener(IRegistryListener<K,E> lsnr);
}
